package cn.uc.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditorActivity extends Activity {
    private EditText editTitle;
    private EditText editContent;
    private Button btnOK;
    private Button btnCancel;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.editor);
        
        editTitle = (EditText)findViewById(R.id.editor_edit_title);
        editContent = (EditText)findViewById(R.id.editor_edit_content);
        
        Bundle sBundle = getIntent().getExtras();
        editTitle.setText(sBundle.getString("title"));
        editContent.setText(sBundle.getString("content"));
       
        btnOK = (Button)findViewById(R.id.editor_btn_ok);
        btnOK.setOnClickListener(new View.OnClickListener() {
            
            public void onClick(View arg0) {
                // XXX Auto-generated method stub
                
                Intent sIntent = new Intent();
                sIntent.setClass(EditorActivity.this, MDiaryActivity.class);
                Bundle data = new Bundle();
                
                data.putString("type", "Text");
                data.putString("title", editTitle.getText().toString());
                data.putString("content", editContent.getText().toString());
                sIntent.putExtras(data);
                //startActivity(sIntent);
                EditorActivity.this.setResult(RESULT_OK, sIntent);  
            
                EditorActivity.this.finish();
            }
        });
        
        btnCancel = (Button)findViewById(R.id.editor_btn_cancel);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            
            public void onClick(View arg0) {
                // XXX Auto-generated method stub
                
                Intent sIntent = new Intent();
                sIntent.setClass(EditorActivity.this, MDiaryActivity.class);  
                EditorActivity.this.setResult(RESULT_OK, sIntent);              
                EditorActivity.this.finish();
            }
        });
    }
}
